import logging

import pytest

from resource.pom.settings import Settings
from utils.manager import Direction


class Test:
    app = Settings

    @pytest.mark.parametrize('setup_teardown', [app.bundle_name], indirect=True)
    def test(self, setup_teardown, device):
        logging.info('步骤1.进入桌面，点击设置-辅助功能，点击辅助功能快捷键')
        device.start_ability(self.app.bundle_name, self.app.ability_name)
        device.dirc_fling(Direction.Down)
        device.click(*self.app.accessibility_features_item)
        device.refresh_layout()
        device.click_element(device.get_element_by_text('辅助功能快捷键'))
        logging.info('预期结果1.进入辅助功能快捷键')
        device.refresh_layout()
        device.assert_text_exist('辅助功能快捷键')
        device.assert_type_exist('Toggle')
        device.assert_text_exist('选择功能')

        logging.info('步骤2.开启/关闭辅助功能快捷键，选择功能')
        switch0 = device.get_element_by_type('Toggle')
        device.click_element(switch0)
        device.click_element(device.get_element_by_text('选择功能'))
        device.refresh_layout()
        font_checkbox0 = device.get_element_by_type('Checkbox', index=0)
        sound_checkbox0 = device.get_element_by_type('Checkbox', index=1)
        color_checkbox0 = device.get_element_by_type('Checkbox', index=2)
        device.click_element(font_checkbox0)
        device.click_element(sound_checkbox0)
        device.click_element(color_checkbox0)
        device.click_element(device.get_element_by_text('确定'))
        logging.info('预期结果2.开启后，连续按电源键三下，可启动无障碍快捷方式，关闭后恢复正常')
        device.refresh_layout()
        switch1 = device.get_element_by_type('Toggle')
        assert switch1.get('checked') != switch0.get('checked')
        device.click_element(device.get_element_by_text('选择功能'))
        device.refresh_layout()
        font_checkbox1 = device.get_element_by_type('Checkbox', index=0)
        sound_checkbox1 = device.get_element_by_type('Checkbox', index=1)
        color_checkbox1 = device.get_element_by_type('Checkbox', index=2)
        device.click_element(device.get_element_by_text('确定'))
        assert font_checkbox0.get('checked') != font_checkbox1.get('checked')
        assert sound_checkbox0.get('checked') != sound_checkbox1.get('checked')
        assert color_checkbox0.get('checked') != color_checkbox1.get('checked')
